import 'package:BeeApp/MainPage/MainModelPage.dart';
import 'package:BeeApp/MainPage/MainToolPage.dart';
import 'package:BeeApp/MainPage/http_request.dart';
import 'package:BeeApp/MainPage/MainGGModelPage.dart';
import 'package:BeeApp/MainPage/MainGGNewsPage.dart';
import 'package:flutter/material.dart';

class MainGGPage extends StatefulWidget {
  MainGGPage({Key key}) : super(key: key);

  @override
  _MainGGPageState createState() => _MainGGPageState();
}

class _MainGGPageState extends State<MainGGPage> {
  GGListModel ggListModel;
  @override
  void initState() {
    super.initState();
    upLoadData();
  }

  void upLoadData() {
    DioUtils.postHttp(
      context,
      "Usercommon/app_notice",
      parameters: {"token": getData("token")},
      onSuccess: (t) {
        print(t);
        MainModel model = MainModel.fromJson(t);
        if (model.code == 1 && model.data != null) {
          if (mounted) {
            setState(() {
              ggListModel = GGListModel.fromJson(t);
            });
          }
        }
      },
      onError: (error) {
        print(error);
      },
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar(context, "公告列表"),
      body: ggListModel == null
          ? Container(
              alignment: Alignment.center,
              child: Text("暂无信息"),
            )
          : ListView.builder(
              itemCount: ggListModel.data.length,
              itemBuilder: (BuildContext context, int index) {
                return InkWell(
                  child: Container(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          padding: EdgeInsets.only(
                              left: setWidth(30),
                              right: setWidth(30),
                              top: setWidth(20)),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                ggListModel.data[index].title,
                                maxLines: 2,
                                overflow: TextOverflow.ellipsis,
                                style: TextStyle(
                                  color: Color(0xFF333333),
                                  fontSize: setFontSize(32),
                                ),
                              ),
                              Row(
                                mainAxisAlignment: MainAxisAlignment.end,
                                children: <Widget>[
                                  Text(
                                    ggListModel.data[index].createtimeText,
                                    style: TextStyle(
                                      color: Color(0xFF999999),
                                      fontSize: setFontSize(30),
                                    ),
                                  )
                                ],
                              ),
                              SizedBox(height: 8),
                            ],
                          ),
                        ),
                        Container(
                          width: 900,
                          height: 1,
                          color: Colors.grey,
                        ),
                      ],
                    ),
                  ),
                  onTap: () {
                    print("object" + index.toString());
                    Navigator.push(
                        context,
                        MaterialPageRoute(
                            builder: (context) => MainGGNewsPage(
                                ggListModel.data[index].id.toString())));
                  },
                );
              },
            ),
    );
  }
}
